package JackSu.project_model;

/**
 * LinkedTest
 *
 * @author Syzer
 * @Description 责任链模式
 * @Date 2021/7/9 17:00
 */
public class LinkedTest {

    private static abstract class Handler {
        private Handler next;

        public Handler getNext() {
            return next;
        }

        public void setNext(Handler next) {
            this.next = next;
        }

        public abstract void handlerRun();

        public void run() {
            handlerRun();
            Handler current = next;
            while(current != null) {
                current.handlerRun();
                current = next.getNext();
            }
        }
    }

    private static class Handler1 extends Handler {

        @Override
        public void handlerRun() {
            System.out.println("谈需求");
        }
    }

    private static class Handler2 extends Handler {

        @Override
        public void handlerRun() {
            System.out.println("开发");
        }
    }

    public static void main(String[] args) {
        Handler handler = new Handler1();
        handler.setNext(new Handler2());
        handler.run();
    }
}
